#include "aio_timeout.h"
#include "../global/head.h"
#include "../socket/head.h"
#include "../xos/head.h"
#include "../buf/head.h"
#include "aio_epoll_notify.h"
#include "aio_impl.h"
#include "aio_helper.h"
#include "aio_tcp.h"

/////////////////////////////////////////////////////////////////////////////////////////
// 
namespace xos
{
    aio_timeout::aio_timeout( aio_impl * pAioImpl ) : m_pAioImpl( pAioImpl )
    {
    }

    aio_timeout::~aio_timeout()
    {
    }

    ////////////////////////////////////////////////////////////////////////////////////
    // 

    int aio_timeout::proc()
    {
        using namespace std;
        int nRet = 0;

        aio_key::LIST & con_list = m_pAioImpl->m_con_list;

        for( aio_key * p = con_list.begin(); p != con_list.end(); )
        {
            aio_key * pC = p;
            p = p->m_pNext;

            if( pC->m_uConUseTime > m_pAioImpl->m_uMaxConnectTime )
            {
                cout << "connect request timeout = " << pC << endl;
                aio_tcp tool( m_pAioImpl );
                pC->m_nCanWriteSize = 0;
                pC->m_bCanWrite = false;
                tool.tcp_recv_connect( pC, 0 );
                pC = 0;
            }
            else
            {
                pC->m_uConUseTime += m_pAioImpl->m_uCheckInterval;
            }
        }

        return nRet;
    }

} // xos
